# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: model_token.py
@time: 2024/11/12 15:16 
@desc: 

"""
from sqlalchemy.sql import func
from sqlalchemy import Column, INT, VARCHAR, DateTime, Enum,UniqueConstraint
from db.base_model import Base


class Token(Base):
    """
    Token 表
    """

    __tablename__ = 'token'
    id = Column(INT, primary_key=True, autoincrement=True, nullable=False, index=True, unique=True)
    user_id = Column(INT, unique=False, nullable=False)
    token = Column(VARCHAR(255), unique=True, nullable=False,comment="ak")
    status = Column(Enum("0", "1", "2"), nullable=False, default="0", comment="0:正常 1:禁止 2:废弃")
    create_time = Column(DateTime, nullable=False, server_default=func.now(), comment="创建时间")
    update_time = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.current_timestamp(),
                         comment="更新时间")
    __table_args__ = (
        UniqueConstraint('user_id', 'token', name='uix_ut'),
        {'mysql_charset': 'utf8mb4'},
    )


STATUS_TOKEN_NORMAL = "0"
STATUS_TOKEN_DORBIDDEN = "2"

